<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix text-left">
        <el-col :span="23">
          <span class="title-icon">法邮追踪号</span>
        </el-col>
      </div>

      <el-form
        ref="ruleForm"
        :rules="rules"
        label-position="left"
        label-width="100px"
        :model="form"
      >
        <el-form-item label="运单号" prop="waybillNos">
          <el-input
            type="textarea"
            v-model="form.waybillNos"
            :rows="5"
            placeholder="请输入运单号(法国),多个换行隔开"
          ></el-input>
        </el-form-item>
        <el-form-item label="打单帐号" prop="accountNo">
          <el-select
            v-model="form.accountNo"
            filterable
            placeholder="请选择"
            style="100%"
          >
            <el-option
              v-for="(item, value) in options"
              :key="value"
              :label="item"
              :value="value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发件人地址" prop="addressCode">
          <el-select
            v-model="form.addressCode"
            filterable
            placeholder="请选择"
            style="100%"
          >
            <el-option
              v-for="(item, value) in addressNameMap"
              :key="value"
              :label="item"
              :value="value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="trackPrintlabelChrornopost"
            >获取法邮追踪号</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import { ajax } from "@/store/yg/common/utils";
import axios from "axios";
import * as constant from "@/store/yg/common/constant";
import { Toast } from "mint-ui";
// import VConsole from "vconsole";
// new VConsole();
export default {
  components: {},
  props: [],
  data() {
    return {
      form: {
        waybillNos: "",
        addressCode: "",
        accountNo: ""
      },
      rules: {
        waybillNos: [
          { required: true, message: "请输入运单号", trigger: "blur" }
        ],
        accountNo: [
          { required: true, message: "请选择打单帐号", trigger: "change" }
        ],
        addressCode: [
          { required: true, message: "请选择发件人地址", trigger: "change" }
        ]
      },

      options: {},

      addressNameMap: {}
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.toGainChrornopostTrack();
  },
  methods: {
    toGainChrornopostTrack() {
      ajax("toGainChrornopostTrack", {}, { type: "mobile" }).then(
        res => {
          console.log(res);
          if (res.code == 200) {
            this.options = res.data;
            this.addressNameMap = res.data2;
          }else{
            Toast("操作失败"+res.message);
          }
        },
        error => {
          console.log(error);
        }
      );
    },
    trackPrintlabelChrornopost() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.saveData();
        } else {
          return false;
        }
      });
    },
    saveData() {
      ajax(
        "trackPrintlabelChrornopost",
        {
          waybillNos: this.form.waybillNos,
          accountNo: this.form.accountNo,
          addressCode: this.form.addressCode
        },
        { type: "mobile" }
      )
        .then(res => {
          console.log(res);
          if (res.code == 200) {
            this.waybillNos = null;
            Toast({
              message: "获取成功",
              iconClass: "icon icon-success"
            });
          } else {
            Toast("获取失败，" + res.message);
          }
        })
        .catch(error => {
          console.log(error);
          Toast("获取失败，" + error.message);
        });
    }
  }
};
</script>
<style></style>
